package edu.ccut.saturn.studio.wfg.policy;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.editpolicies.ResizableEditPolicy;
import org.eclipse.gef.handles.AbstractHandle;
import org.eclipse.gef.handles.NonResizableHandleKit;
import org.eclipse.gef.handles.ResizableHandleKit;
import org.eclipse.swt.graphics.Color;

public class ResizaEdidPolicyNoHandle extends ResizableEditPolicy {
	@Override
	protected Rectangle getInitialFeedbackBounds() {
		Rectangle r = Rectangle.SINGLETON;
		r.setBounds(new Rectangle(super.getInitialFeedbackBounds().x
				+ super.getInitialFeedbackBounds().width / 2 - 25, super
				.getInitialFeedbackBounds().y
				+ super.getInitialFeedbackBounds().height / 2 - 25, 50, 50));
		return r;
	}

	private int directions = -1;

	@SuppressWarnings("unchecked")
	protected List createSelectionHandles() {
		List list = new ArrayList();

		if (directions == 0)
			NonResizableHandleKit.addHandles((GraphicalEditPart) getHost(),
					list);
		else if (directions != -1) {
			ResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(),
					list);
			if ((directions & PositionConstants.EAST) != 0)
				ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.EAST);
			else
				NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.EAST);
			if ((directions & PositionConstants.SOUTH_EAST) == PositionConstants.SOUTH_EAST)
				ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.SOUTH_EAST);
			else
				NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.SOUTH_EAST);
			if ((directions & PositionConstants.SOUTH) != 0)
				ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.SOUTH);
			else
				NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.SOUTH);
			if ((directions & PositionConstants.SOUTH_WEST) == PositionConstants.SOUTH_WEST)
				ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.SOUTH_WEST);
			else
				NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.SOUTH_WEST);
			if ((directions & PositionConstants.WEST) != 0)
				ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.WEST);
			else
				NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.WEST);
			if ((directions & PositionConstants.NORTH_WEST) == PositionConstants.NORTH_WEST)
				ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.NORTH_WEST);
			else
				NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.NORTH_WEST);
			if ((directions & PositionConstants.NORTH) != 0)
				ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.NORTH);
			else
				NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.NORTH);
			if ((directions & PositionConstants.NORTH_EAST) == PositionConstants.NORTH_EAST)
				ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.NORTH_EAST);
			else
				NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
						list, PositionConstants.NORTH_EAST);
		} else
			CustomResizableHandleKit.addHandles((GraphicalEditPart) getHost(),
					list);
		changGColor(list);
		return list;
	}

	void changGColor(List<?> list) {
		AbstractHandle ff;
		for (int i = 0; i < list.size(); i++) {
			ff = (AbstractHandle) list.get(i);
			ff.setBackgroundColor(new Color(null, 115, 115, 115));
			ff.setForegroundColor(new Color(null, 115, 115, 115));
		}
	}
}
